package com.xunyin.enums;

/**
 * @author jthong
 * @Description:订单状态
 * @Version 1.0.0
 * @Date 2020/01/16 10:10
 */
public enum OrderStatusEnum {
    /***
     * 待支付
     */
    WAIT_PAY(0, "待支付"),

    /***
     * 已支付
     */
    PAID(1, "已支付"),

    /***
     * 服务中
     */
    IN_SERVICE(2, "服务中"),

    /***
     * 已取消
     */
    CANCELLED(3, "已取消"),

    /***
     * 已完成
     */
    COMPLETED(4, "已完成"),

    /***
     * 已退款
     */
    REFUNDED(5, "已退款"),
    ;


    private final String name;
    private final int value;

    OrderStatusEnum(int value, String name) {
        this.name = name;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return value;
    }

    public short getIndexShortValue() {
        return (short) value;
    }

    public static OrderStatusEnum parse(Integer value) {
        if (value == null) {
            return throwParseException(value);
        }
        for (OrderStatusEnum e : OrderStatusEnum.values()) {
            if (e.getValue() == value) {
                return e;
            }
        }
        return throwParseException(value);
    }

    private static OrderStatusEnum throwParseException(Integer value) {
        throw new IllegalArgumentException(value + " can not parse to " + OrderStatusEnum.class.getName());
    }

    public static String getNameByValue(Integer value) {
        if (value == null) {
            return "";
        }
        for (OrderStatusEnum e : OrderStatusEnum.values()) {
            if (e.getValue() == value) {
                return e.getName();
            }
        }
        return "";
    }
}
